// pages/welcome/welcome.js
import Dialog from '@vant/weapp/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    second: 3
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 启动定时器
    const t = setInterval(() => {
      if (this.data.second <= 1) {
        clearInterval(t);
        this.doJump();
      }
      this.setData({
        second: this.data.second - 1
      })
    }, 1000)
  },
  /**
   * 跳转
   */
  doJump() {
    // 跳转到上次选择的tab页
    const openid = getApp().globalData.openid;
    if (!openid) {
      Dialog.alert({
        message: '连接服务器失败，请联系管理员',
      }).then(() => {
        // on close
      });
      return;
    }
    let url = wx.getStorageSync('tabselected') || 'trans';

    if (url === 'trans') {
      url = "/pages/trans/trans";
    } else if (url === 'preboxing') {
      url = "/pages/preboxing/preboxing";
    } else {
      url = "/pages/register/register";
    }
    // console.log('url', url);
    wx.switchTab({
      url: url,
      fail: (error) => {
        console.log(error);
      }
    })
  }
})